<template>
  <div class="index">


    <main>
      <!-- 轮播图区域 -->
      <section class="carousel-wrapper">
        <div class="carousel-container">
          <div
            v-for="(slide, index) in carouselSlides"
            :key="index"
            class="carousel-slide"
            :class="{ active: index === currentSlide }"
          >
            <img :src="slide.image" :alt="slide.title" />
            <div class="overlay"></div>
            <div class="content">
              <h2>{{ slide.title }}</h2>
              <p>{{ slide.description }}</p>
            </div>
          </div>
        </div>

        <!-- 轮播控制按钮 -->
        <button class="carousel-control prev" @click="prevSlide">
          <i class="fa fa-angle-left"></i>
        </button>
        <button class="carousel-control next" @click="nextSlide">
          <i class="fa fa-angle-right"></i>
        </button>

        <!-- 轮播指示器 -->
        <div class="carousel-indicators">
          <span
            v-for="(slide, index) in carouselSlides"
            :key="index"
            :class="{ active: index === currentSlide }"
            @click="goToSlide(index)"
          ></span>
        </div>
      </section>

      <!-- 特色分类 -->
      <section class="categories container">
        <h2>咖啡豆口味展示</h2>
        <p>探索不同种类的咖啡豆，找到最适合您口味的选择</p>
        <div class="grid">
          <router-link
              v-for="cat in product_type.slice(4,7)"
              :key="cat.id"
              :to="{name:producttype, params: { id: cat.id }}"
              class="card"
          >
            <img
    :src="cat.beantype_image
      ? (cat.beantype_image.startsWith('http') ? cat.beantype_image : `http://127.0.0.1:8000/static/${cat.beantype_image}`)
      : ''"
    :alt="cat.name"
  />

            <div class="overlay">
              <h3>{{ cat.name }}</h3>
<!--              <p>{{ cat.desc }}</p>-->
            </div>
          </router-link>
        </div>
      </section>


      <!-- 热门产地 -->
      <section class="origins container">
        <h2>来自中国的优质产地</h2>
        <p>每一款咖啡豆都承载着其产地的独特风土人情</p>
        <div class="grid">
          <router-link
              v-for="o in origins"
              :key="o.name"
              :to="o.link"
              class="origin"
          >
            <img :src="o.img" :alt="o.name"/>
            <div class="mask">
              <h3>{{ o.name }}</h3>
            </div>
          </router-link>
        </div>

      </section>


      <!-- 本周精选 -->
      <section class="featured container">
        <div class="header">
          <div>
            <h2>本周精选</h2>
            <p>我们为您精心挑选的优质咖啡豆</p>
          </div>
          <router-link to="/all-coffees">查看全部 <i class="fa fa-angle-right"></i></router-link>
        </div>
        <div class="grid">
          <div v-for="item in productlist.slice(0,8)" :key="item.id" class="product-card">
            <div class="img">
  <!-- 处理图片路径和空值情况 -->
  <img
    :src="item.image_urls && item.image_urls.length > 0
      ? (item.image_urls[0].startsWith('http') ? item.image_urls[0] : `http://127.0.0.1:8000/static/${item.image_urls[0]}`)
      : ''"
    :alt="item.name"
  />
  <span class="tag">{{ item.stock }}</span>
  <span v-if="item.discount" class="discount">{{ item.description }}</span>
  <button class="wish" @click="addTofavorite(item)"><i class="fa fa-heart-o" ></i></button>
</div>
            <div class="info">
              <router-link :to="'/productdetail?id=' + item.id">
              <h3>{{ item.name }}</h3>
              </router-link>
              <p>{{ item.description }}</p>
              <div class="bottom">
                <div class="price">
                  <span class="now">¥{{ item.price.toFixed(2) }}</span>
                  <span v-if="item.original_price" class="old">¥{{ item.original_price.toFixed(2) }}</span>
                </div>
                <button class="cart" @click="addToCart(item)"><i class="fa fa-shopping-cart"></i></button>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- 优惠活动 -->
      <section class="promotion">
        <div class="inner">
          <div class="text">
            <span class="label">限时特惠</span>
            <h2>购买任意两款咖啡豆</h2>
            <h3>即享85折优惠</h3>
            <p>活动期间，购买任意两款咖啡豆即可享受85折优惠，更有机会获得限量版咖啡杯套装。</p>
            <router-link to="/all-coffees" class="btn-white">立即选购</router-link>
          </div>
          <img src="https://picsum.photos/id/312/800/600" alt="优惠" />
        </div>
      </section>

    </main>

    <!-- Footer -->
    <Footer />

    <!-- 返回顶部 -->
    <transition name="fade">
      <button class="back-top" v-show="showTop" @click="toTop">
        <i class="fa fa-arrow-up"></i>
      </button>
    </transition>
  </div>
</template>

<script>
// 1. 正确创建Axios实例（解决this.$axios未定义问题）
import api from '@/api/request'
export default {
  name: 'Index',
  data() {
    return {
      product_type: [],
      productlist:[],
      mobileMenuOpen: false,
      showTop: false,
      searchQuery: '',
      email: '',
      currentSlide: 0,
      carouselSlides: [
        { image: 'https://picsum.photos/id/431/1600/900', title: '普洱小粒咖啡', description: '感受茉莉花香与柑橘酸的完美融合' },
        { image: 'https://picsum.photos/id/766/1600/900', title: '云南孟连精品卡蒂姆', description: '焦糖甜感与坚果风味的平衡' },
        { image: 'https://picsum.photos/id/493/1600/900', title: '海南兴隆罗布斯塔', description: '黑醋栗与葡萄柚的明亮酸度' }
      ],
      origins: [
        { name: '云南', img: 'https://picsum.photos/id/431/400/400', link: '#' },
        { name: '海南', img: 'https://picsum.photos/id/766/400/400', link: '#' },
        { name: '四川', img: 'https://picsum.photos/id/493/400/400', link: '#' },
        { name: '福建', img: 'https://picsum.photos/id/225/400/400', link: '#' }
      ],
      featured: [/* 保持原数据不变 */],
      reviews: [/* 保持原数据不变 */],
      blogs: [/* 保持原数据不变 */],
      carouselInterval: null,
    }
  },
  mounted() {
    window.addEventListener('scroll', this.handleScroll)
    this.startCarousel()
    // 3. 修正：在Vue 2的mounted钩子中调用函数（替代无效的onMounted）
    this.funprrodect_typelist();
  },
  beforeDestroy() {
    window.removeEventListener('scroll', this.handleScroll)
    clearInterval(this.carouselInterval)
  },
  methods: {
    index_products:function (){
      this.$axios.get('http://127.0.0.1:8000/coffeeProduct/')
      .then(response => {
        // 后端返回结构为 { code, message, data }
        if (response.code === 200) {
          console.log(response.data)
          // 从返回数据的data字段中获取商品列表
          this.productlist = response.data;
        } else {
          console.log('获取商品失败:', response.message);
        }
      })
      .catch(error => {
        console.error('请求商品接口出错:', error);
      });
    },
    toggleMenu() {
      this.mobileMenuOpen = !this.mobileMenuOpen
    },
    async addToCart(product) {
      try {
        console.log(11111111,product)
        await api.post('/cart', {
          product_id: product.id,
          product_type: 'coffee',
          quantity: 1
        })
        alert("已成功添加至购物车")
        window.location.reload();
      } catch (e) {
        console.error('422 错误详情：', e.response?.data);
        console.error('添加失败', e);
      }
    },
    async addTofavorite(product) {
      this.isSubmitting = true;
      try {
        await api.post('/favorite/add', {
          product_id: product.id,
          product_type: 'coffee',
        })
        this.$message.success("已成功添加至收藏");
      } catch (e) {
          console.error('完整错误对象:', e);
    let errorMsg = "添加收藏失败，请稍后再试"; // 默认错误提示

    if (e.response?.status === 400 || e.response?.status === 500) {
      // 尝试解析 JSON 或直接使用字符串
      try {
        const data = typeof e.response.data === "string"
          ? JSON.parse(e.response.data)
          : e.response.data;
        errorMsg = data.detail || data.error || errorMsg;
      } catch (parseError) {
        errorMsg = e.response.data || errorMsg;
      }
    }

    this.$message.warning(errorMsg);
  } finally {
    this.isSubmitting = false;
  }
  },
    funprrodect_typelist() {
      // 现在会执行，弹出11
      api.get("/coffeeCategory/") // 用基础路径+接口名，简化URL
        .then((response) => {
          console.log("接口返回完整数据：", response); // 关键：先打印数据，确认格式

        // 1. 验证数据格式：确保是数组（若后端返回 {data: []}，则取 response.data.data；若直接返回数组，则取 response.data）
        const resData = Array.isArray(response.data) ? response.data : response;
        console.log(resData)
        // 2. 用数组变异方法赋值，确保响应式（清空原数组后添加新数据）
        this.product_type.splice(0, this.product_type.length, ...resData);
        // 或简化：this.product_type = [...resData];（展开运算符创建新数组，保持响应式）

        console.log("响应式数组赋值后：", this.product_type); // 验证是否成功挂载
        })
        .catch((error) => {
          alert(33333);
          alert("错误信息：" + error.message); // 显示具体错误信息（便于调试）
        });
    },
    handleScroll() {
      this.showTop = window.scrollY > 300
    },
    toTop() {
      window.scrollTo({ top: 0, behavior: 'smooth' })
    },
    startCarousel() {
      // 轮播逻辑（示例：3秒切换一次幻灯片）
      this.carouselInterval = setInterval(() => {
        this.currentSlide = (this.currentSlide + 1) % this.carouselSlides.length;
      }, 3000);
    },
    nextSlide() {
      this.currentSlide = (this.currentSlide + 1) % this.carouselSlides.length
    },
    prevSlide() {
      this.currentSlide =
        (this.currentSlide - 1 + this.carouselSlides.length) % this.carouselSlides.length
    },
    goToSlide(index) {
      clearInterval(this.carouselInterval)
      this.currentSlide = index
      this.startCarousel()
    },
    subscribe() {
      alert(`感谢订阅：${this.email}`)
      this.email = ''
    },
    starCls(index, rating) {
      return rating >= index ? 'fa fa-star' : rating >= index - 0.5 ? 'fa fa-star-half-o' : 'fa fa-star-o'
    }
  },
  created:function(){
    this.index_products()
  }
}
</script>

<style scoped>
:root {
  --primary: #8B5A2B;
  --secondary: #D2B48C;
  --accent: #CD853F;
  --light: #F5F5DC;
  --dark: #3E2723;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

/* 顶部通知栏 */
.topbar {
  background: var(--primary);
  color: #fff;
  text-align: center;
  padding: 6px 0;
  font-size: 14px;
}
.topbar a {
  text-decoration: underline;
  margin-left: 4px;
}

/* 轮播图 */
.carousel-wrapper {
  position: relative;
  height: 50vh;
  min-height: 300px;
  max-height: 500px;
  overflow: hidden;
}
.carousel-container {
  position: relative;
  width: 100%;
  height: 100%;
}
.carousel-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1s ease;
}
.carousel-slide.active {
  opacity: 1;
}
.carousel-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
}
.content {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding: 0 2rem;
  color: #fff;
}
.content h2 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.content p {
  font-size: clamp(1rem, 2vw, 1.25rem);
  margin-bottom: 1.5rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  transition: background 0.3s;
}
.btn-primary:hover {
  background: var(--dark);
}

.carousel-control {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 2.5rem;
  height: 2.5rem;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  transition: background 0.3s;
}
.carousel-control.prev {
  left: 1rem;
}
.carousel-control.next {
  right: 1rem;
}
.carousel-control:hover {
  background: rgba(255, 255, 255, 0.4);
}

.carousel-indicators {
  position: absolute;
  bottom: 1.5rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}
.carousel-indicators span {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: all 0.3s;
}
.carousel-indicators span.active {
  background: #fff;
  width: 2rem;
  border-radius: 0.375rem;
}

/* 分类 */
.categories {
  padding: 3rem 0;
  background: #fff;
}
.categories h2 {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.5rem;
}
.categories > p {
  color: #4b5563;
  text-align: center;
  max-width: 42rem;
  margin: 0 auto 2.5rem;
}
.categories .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}
.card {
  position: relative;
  border-radius: 0.75rem;
  overflow: hidden;
  height: 16rem;
  transition: transform 0.3s, box-shadow 0.3s;
}
.card:hover {
  transform: scale(1.05);
}
.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.7s;
}
.card:hover img {
  transform: scale(1.1);
}
.card .overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1.5rem;
  color: #fff;
}
.card h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.card p {
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

/* 产地 */
.origins {
  padding: 3rem 0;
  background: #f9fafb;
}
.origins h2 {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.5rem;
}
.origins > p {
  color: #4b5563;
  text-align: center;
  max-width: 42rem;
  margin: 0 auto 2.5rem;
}
.origins .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
}
.origin {
  position: relative;
  border-radius: 0.75rem;
  overflow: hidden;
  aspect-ratio: 1;
}
.origin img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.origin .mask {
  position: absolute;
  inset: 0;
  background: rgba(139, 90, 43, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s;
}
.origin:hover .mask {
  background: rgba(139, 90, 43, 0.8);
}
.origin h3 {
  color: #fff;
  font-weight: 700;
  font-size: 1.125rem;
  text-align: center;
}
.more {
  text-align: center;
  margin-top: 2rem;
}
.more a {
  color: var(--primary);
  font-weight: 500;
}
.more a:hover {
  text-decoration: underline;
}

/* 精选商品 */
.featured {
  padding: 3rem 0;
  background: #fff;
}
.featured .header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 2.5rem;
  flex-wrap: wrap;
}
.featured h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.featured p {
  color: #4b5563;
}
.featured .grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}
.product-card {
  background: #fff;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.3s;
}
.product-card:hover {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.product-card .img {
  position: relative;
}
.product-card .img img {
  width: 100%;
  height: 12rem;
  object-fit: cover;
}
.tag,
.discount {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  color: #fff;
  background: var(--primary);
}
.discount {
  left: auto;
  right: 0.75rem;
  background: #ef4444;
}
.wish {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  background: rgba(255, 255, 255, 0.8);
  border: none;
  border-radius: 50%;
  color: #6b7280;
  cursor: pointer;
  transition: background 0.3s, color 0.3s;
}
.wish:hover {
  background: var(--primary);
  color: #fff;
}
.product-card .info {
  padding: 1rem;
}
.stars {
  display: flex;
  align-items: center;
  color: var(--primary);
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
}
.stars span {
  color: #6b7280;
  margin-left: 0.25rem;
}
.product-card h3 {
  font-weight: 500;
  color: #111827;
  margin-bottom: 0.25rem;
  transition: color 0.3s;
}
.product-card:hover h3 {
  color: var(--primary);
}
.product-card p {
  color: #6b7280;
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.price .now {
  font-weight: 700;
  color: var(--primary);
  font-size: 1.125rem;
}
.price .old {
  color: #9ca3af;
  text-decoration: line-through;
  margin-left: 0.5rem;
  font-size: 0.875rem;
}
.cart {
  width: 2.5rem;
  height: 2.5rem;
  background: rgba(139, 90, 43, 0.1);
  border: none;
  border-radius: 50%;
  color: var(--primary);
  cursor: pointer;
  transition: background 0.3s, color 0.3s;
   z-index: 999; /* 确保按钮在最上层 */
  pointer-events: auto; /* 确保可以接收点击事件 */
}
.cart:hover {
  background: var(--primary);
  color: #fff;
}

/* 促销活动 */
.promotion {
  padding: 3rem 0;
  background: #f3f4f6;
}
.promotion .inner {
  background: linear-gradient(90deg, var(--primary), var(--dark));
  border-radius: 1rem;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.text {
  padding: 2.5rem 2rem;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.text .label {
  color: var(--secondary);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}
.text h2 {
  font-size: clamp(1.5rem, 3vw, 2.5rem);
  font-weight: 700;
  line-height: 1.25;
  margin: 0.25rem 0 0.75rem;
}
.text h3 {
  font-size: clamp(1.25rem, 2.5vw, 2rem);
  margin-bottom: 1.25rem;
}
.text p {
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 2rem;
}
.btn-white {
  align-self: flex-start;
  background: #fff;
  color: var(--primary);
  font-weight: 600;
  padding: 0.875rem 2rem;
  border-radius: 0.5rem;
  transition: background 0.3s, color 0.3s;
}
.btn-white:hover {
  background: var(--secondary);
  color: var(--dark);
}
.promotion img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
@media (max-width: 768px) {
  .promotion .inner {
    grid-template-columns: 1fr;
  }
}

/* 客户评价 */
.reviews {
  padding: 3rem 0;
  background: #fff;
}
.reviews h2 {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.5rem;
}
.reviews > p {
  color: #4b5563;
  text-align: center;
  max-width: 42rem;
  margin: 0 auto 2.5rem;
}
.reviews .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}
.review-card {
  background: #f9fafb;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.3s;
}
.review-card:hover {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.review-card .stars {
  margin-bottom: 1rem;
}
.quote {
  color: #374151;
  font-style: italic;
  margin-bottom: 1.5rem;
}
.user {
  display: flex;
  align-items: center;
}
.user img {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  margin-right: 1rem;
}
.user h4 {
  font-weight: 500;
  color: #111827;
}
.user span {
  color: #6b7280;
  font-size: 0.875rem;
}

/* 咖啡知识 */
.blogs {
  padding: 3rem 0;
  background: #f9fafb;
}
.blogs .header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 2.5rem;
  flex-wrap: wrap;
}
.blogs h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.blogs p {
  color: #4b5563;
}
.blogs .grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}
.blog-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s, box-shadow 0.3s;
}
.blog-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px -8px rgba(0, 0, 0, 0.1);
}
.blog-card img {
  width: 100%;
  height: 12rem;
  object-fit: cover;
  transition: transform 0.5s;
}
.blog-card:hover img {
  transform: scale(1.05);
}
.blog-card .content {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}
.blog-card .tag {
  align-self: flex-start;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--primary);
  background: rgba(139, 90, 43, 0.15);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
}
.blog-card h3 {
  font-weight: 600;
  font-size: 1.125rem;
  margin: 0.75rem 0 0.5rem;
  line-height: 1.4;
}
.blog-card p {
  color: #6b7280;
  font-size: 0.875rem;
  line-height: 1.5;
  margin-bottom: 1rem;
  flex: 1;
}
.read {
  font-size: 0.875rem;
  color: var(--primary);
  font-weight: 500;
}
.read:hover {
  text-decoration: underline;
}

/* 订阅 */
.subscribe {
  padding: 3rem 0;
  background: #fff;
  text-align: center;
}
.subscribe h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.subscribe p {
  color: #4b5563;
  margin-bottom: 2rem;
}
.subscribe form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 32rem;
  margin: 0 auto;
}
@media (min-width: 640px) {
  .subscribe form {
    flex-direction: row;
  }
}
.subscribe input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
}
.subscribe button {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.3s;
}
.subscribe button:hover {
  background: var(--dark);
}
.subscribe small {
  color: #6b7280;
  font-size: 0.875rem;
  display: block;
  margin-top: 1rem;
}

/* 顶部导航 */
.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.main-nav .nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 22px;
  font-weight: 700;
  color: #8B5A2B;
}
.search-box {
  position: relative;
  flex: 1;
  max-width: 320px;
  margin: 0 24px;
}
.search-box input {
  width: 100%;
  padding: 8px 36px 8px 16px;
  border-radius: 20px;
  border: 1px solid #ccc;
}
.search-box i {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #666;
}
.icons {
  display: flex;
  gap: 16px;
  align-items: center;
}
.icon-btn {
  position: relative;
  font-size: 20px;
  color: #333;
}
.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #4ade80;
  color: #fff;
  font-size: 12px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
}
.desktop-menu {
  display: flex;
  gap: 32px;
  justify-content: center;
  background: #8B5A2B;
  padding: 10px 0;
}
.desktop-menu a {
  color: #fff;
  padding: 4px 12px;
  border-radius: 4px;
  transition: background 0.3s;
}
.desktop-menu a.active,
.desktop-menu a:hover {
  background: #3E2723;
}
.mobile-menu {
  display: none;
  flex-direction: column;
  background: #fff;
  border-top: 1px solid #eee;
}
.mobile-menu a {
  padding: 12px 24px;
  border-bottom: 1px solid #eee;
  color: #333;
}
.slide-enter-active,
.slide-leave-active {
  transition: max-height 0.3s ease;
  max-height: 300px;
  overflow: hidden;
}
.slide-enter-from,
.slide-leave-to {
  max-height: 0;
}
@media (max-width: 768px) {
  .search-box,
  .desktop-menu {
    display: none;
  }
  .hamburger {
    display: block;
  }
  .mobile-menu {
    display: flex;
  }
}

/* 页脚 */
.site-footer {
  background: var(--dark);
  color: #fff;
  padding: 2.5rem 0 1.5rem;
}
.footer-inner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 2rem;
}
.footer-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.375rem;
  font-weight: 700;
  margin-bottom: 1rem;
}
.footer-brand i {
  color: var(--secondary);
}
.footer-social {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}
.footer-social a {
  width: 2.25rem;
  height: 2.25rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1.125rem;
  transition: background 0.3s;
}
.footer-social a:hover {
  background: rgba(255, 255, 255, 0.2);
}
.footer-col h4 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
}
.footer-col ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.footer-col li {
  margin-bottom: 0.5rem;
}
.footer-col a {
  color: #9ca3af;
  text-decoration: none;
  transition: color 0.3s;
}
.footer-col a:hover {
  color: #fff;
}
.contact-list li {
  display: flex;
  align-items: center;
  color: #9ca3af;
}
.contact-list i {
  margin-right: 0.5rem;
}
.footer-bottom {
  text-align: center;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  color: #9ca3af;
  font-size: 0.875rem;
}

/* 返回顶部 */
.back-top {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  width: 3rem;
  height: 3rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  z-index: 50;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  transition: background 0.3s;
}
.back-top:hover {
  background: var(--dark);
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}
.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>